﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthOnline.Business;
using MyHealthOnline.Dal.Generated.EntityClasses;

namespace MyHealthOnline.Specialist
{
    public partial class OpenConsult : System.Web.UI.Page
    {
        public int ConsultId
        {
            get
            {
                return Convert.ToInt32(Request.QueryString["ConsultId"]);
            }
        }

        public ListItemCollection ActionListItems
        {
            get
            {
                ListItemCollection coll = new ListItemCollection();
                coll.AddRange(new ListItem[]
                    {
                        new ListItem("Choose an action"),
                        new ListItem("Ask a Question"),
                        new ListItem("End of consult"),
                        //new ListItem("End of consult advanced","2"),
                        new ListItem("Send Questionnaire"),
                        new ListItem("Select next consult date")//,
                //        new ListItem("Send Message")
                    });
                return coll;
            }
        }

        public ConsultEntity Consult
        {
            get
            {
                return ConsultBusiness.GetConsult(ConsultId);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                litName.Text = Consult.Pacient.Name;
                litPatientNumber.Text = Consult.Pacient.Id.ToString();
                litDateOfBirth.Text = Consult.Pacient.Birthday.ToString();
                litEmail.Text = Consult.Pacient.Email;
                litMobile.Text = Consult.Pacient.Phone;
                litConsultDate.Text = Consult.ConsultDate.ToString();
                if(Consult.Status!="Closed")
                {
                    pnlActions.Visible = true;
                    ddlActions.DataSource = ActionListItems;
                    ddlActions.DataBind();
                }
                else
                {
                    pnlActions.Visible = false;
                }
                ucMessageHistory.SetDataSource(QuestionBusiness.GetQuestionsByConsult(ConsultId));
                ucAppointments.ConsultId = ConsultId;
                ucEnd.ConsultId = ConsultId;
                ucQuestions.ConsultId = ConsultId;
                ucQuestionnaire.ConsultId = ConsultId;
                ucEndConsult.ConsultId = ConsultId;
                ucNextAppointment.ConsultId = ConsultId;
                ucMessage.ConsultId = ConsultId;
            }

        }

        protected void ddlActions_SelectedIndexChanged(object sender, EventArgs e)
        {
            ucQuestions.Visible = false;
            ucQuestionnaire.Visible = false;
            ucEndConsult.Visible = false;
            ucNextAppointment.Visible = false;
            ucMessage.Visible = false;

            if (ddlActions.SelectedValue == "Ask a Question")//"Ask a Question"
            {
                ucQuestions.Visible = true;
            }
            else if (ddlActions.SelectedValue == "End of consult")//"End of consult"
            {
                ucEndConsult.Visible = true;
            }
            else if (ddlActions.SelectedValue == "2")//"End of consult advanced"
            {
            }
            else if (ddlActions.SelectedValue == "Send Questionnaire")//"Send Questionnaire"
            {
                ucQuestionnaire.Visible = true;
            }
            else if (ddlActions.SelectedValue == "Select next consult date")//"Select next consult date"
            {
                ucNextAppointment.Visible = true;
            }
            else if (ddlActions.SelectedValue == "Send Message")//"Send Message"
            {
                ucMessage.Visible = true;
            }
        }

    }
}